﻿@using Coslen.Framework
@using MvcPaging
@model Coslen.Framework.Logging.LoggingIndexModel
           
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_FullWidthLayout.cshtml";
}

<link href="@Url.Content("~/Areas/Admin/Content/admin.css")" rel="stylesheet" type="text/css" />

<h2>Index</h2>

<div class="grid-options">
        View : 
        <strong>List</strong>
        | @Html.ActionLink("Manage", "Manage")
</div>  

@using (Html.BeginForm("Index", "Logging", new { page = 0 }, FormMethod.Get, new { id = "myform" }))
{
    <div class="grid-filter">
        <div class="inner">
            Logger : @Html.DropDownList("LoggerProviderName", Model.LoggerProviderNameList)
            Level : @Html.DropDownList("LogLevel", Model.LogLevelList)
            For : @Html.DropDownList("Period", Model.PeriodList)
            <input id="btnGo" name="btnGo" type="submit" value="Apply Filter" />
        </div>
    </div>

    <div class="grid-header">
        <div class="grid-results">
            <div class="inner">
                <span style="float: left">
                    @string.Format("{0} records found. Page {1} of {2}", Model.TotalItemCount, Model.CurrentPageIndex, Model.TotalPageCount)
                </span><span style="float: right">Show @Html.DropDownList("PageSize", Model.PageSizeList, new { onchange = "document.getElementById('myform').submit()" })
                    results per page </span>
                <div style="clear: both">
                </div>
            </div>
        </div>
        <div class="paging">
            <div class="pager">
                @Html.Pager(Model.LogEvents.PageSize, Model.LogEvents.PageNumber, Model.LogEvents.TotalItemCount, new { LoggerProviderName = ViewBag.LoggerProviderName, LogLevel = ViewBag.LogLevel, Period = ViewBag.Period, PageSize = ViewBag.PageSize })
            </div>
        </div>
    </div>

}

@if (!Model.LogEvents.Any())
{ 
    <p>No results found</p>
}
else
{
    <div class="grid-container">
        <table class="grid">
            <tr>
                <th>
                </th>
                <th>
                    #
                </th>
                <th>
                    Log
                </th>
                <th>
                    Date
                </th>
                <th style='white-space: nowrap;'>
                    Time ago
                </th>
                <th>
                    Host
                </th>
                <th>
                    Source
                </th>
                <th>
                    Message
                </th>
                <th>
                    Type
                </th>
                <th>
                    Level
                </th>
            </tr>
            @foreach (var item in Model.LogEvents.Select((x, i) => new { Data = x, Index = i }))
            {
                <tr class="@(item.Index % 2 == 1 ? "alt" : "")">
                    <td>
                        @Html.ActionLink("Details", "Details", new { id = item.Data.Id.ToString(), loggerProviderName = item.Data.LoggerProviderName })
                    </td>
                    <td>
                        @item.Index.ToString()
                    </td>
                    <td>
                        @item.Data.LoggerProviderName
                    </td>
                    <td style='white-space: nowrap;'>
                        @String.Format("{0:g}", item.Data.LogDate.ToLocalTime())
                    </td>
                    <td style='white-space: nowrap;'>
                        @item.Data.LogDate.ToLocalTime().TimeAgoString()
                    </td>
                    <td>
                        @item.Data.MachineName
                    </td>
                    <td>
                        @item.Data.Source
                    </td>
                    <td>
                        <pre>@item.Data.Message.WordWrap(80)</pre>
                    </td>
                    <td>
                        @item.Data.Type
                    </td>
                    <td>
                        @item.Data.Level.ToLower().ToPascalCase()
                    </td>
                </tr>
            }
        </table>
    </div>
}
<div class="grid-header">
    <div class="paging">
        <div class="pager">
            @Html.Pager(Model.LogEvents.PageSize, Model.LogEvents.PageNumber, Model.LogEvents.TotalItemCount, new { LoggerProviderName = ViewBag.LoggerProviderName, LogLevel = ViewBag.LogLevel, Period = ViewBag.Period, PageSize = ViewBag.PageSize })
        </div>
    </div>
</div>
